/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package accesoDatos;
import logica.*;
import java.sql.*;

public class DAOAdmin {
    
    private FachadaBD fachada;
    
    public DAOAdmin(){
        fachada = new FachadaBD();
    }
    
    public int guardarAdmin(Admin admin){
        String sql="INSERT INTO Administrador (id_admin, nombre, usuario, passwd) VALUES ('"
                + admin.getId() + "', '" + admin.getNombre() + "', '" + admin.getUsuario() + "', '"
                + admin.getPassword() + "')";
        
        try{
            Connection c=fachada.conectar();
            Statement sentencia=c.createStatement();
            int numFilas= sentencia.executeUpdate(sql);
            fachada.desconectar(c);
            return numFilas;
        }
        catch(SQLException e){}
        catch(Exception e){}
        return -1;
    }
    
    public Admin verificarAdministrador(String user,String pass){
        Admin a=null;
        String sql = "SELECT * FROM administrador "
                + "WHERE usuario='" + user + "' AND passwd='" + pass + "'";
        
       try{
            Connection c= fachada.conectar();
            Statement sentencia = c.createStatement();
            ResultSet res=sentencia.executeQuery(sql);
            
            while(res.next()){
                a= new Admin();
                a.setId(res.getString(1));
                a.setNombre(res.getString(2));
                a.setUsuario(res.getString(3));
                a.setPasswd(res.getString(4));
            }
            fachada.desconectar(c);
        }
        catch(SQLException e){}
        catch(Exception e){}
       return a;
    }
    
}
